package csp.pdt.demo.rutbai;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
/*
 *  Chapter04 : 
 *  Bài tập : 3 
 *  Mục đích : Thực hành viết game rút bài ngẩu nhiên trong 52 lá bài
 * 
 */
public class RutBaiActivity extends Activity {
	
	int[] bich = {R.drawable.bich0,R.drawable.bich1,R.drawable.bich2,R.drawable.bich3,R.drawable.bich4,R.drawable.bich5,R.drawable.bich6,R.drawable.bich7,R.drawable.bich8,R.drawable.bich9,R.drawable.bich10,R.drawable.bich11,R.drawable.bich12} ;
	int[] ro = {R.drawable.ro0,R.drawable.ro1,R.drawable.ro2,R.drawable.ro3,R.drawable.ro4,R.drawable.ro5,R.drawable.ro6,R.drawable.ro7,R.drawable.ro8,R.drawable.ro9,R.drawable.ro10,R.drawable.ro11,R.drawable.ro12} ;
	int[] chuong = {R.drawable.chuong0,R.drawable.chuong1,R.drawable.chuong2,R.drawable.chuong3,R.drawable.chuong4,R.drawable.chuong5,R.drawable.chuong6,R.drawable.chuong7,R.drawable.chuong8,R.drawable.chuong9,R.drawable.chuong10,R.drawable.chuong11,R.drawable.chuong12} ;
	int[] co = {R.drawable.bich0,R.drawable.bich1,R.drawable.bich2,R.drawable.bich3,R.drawable.bich4,R.drawable.bich5,R.drawable.bich6,R.drawable.bich7,R.drawable.bich8,R.drawable.bich9,R.drawable.bich10,R.drawable.bich11,R.drawable.bich12} ;
	Button btnRutBai ;
	ImageButton imageButton ; 
	/*
	String[] loaiBai ={"Co","Ro","Chuong","Bich"};
	String[] thuTuBai = {"Ach","Hai","Ba","Bon","Nam","Sau","Bay","Tam","Chin","Muoi","Boi","Dam","Gia"}; */
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        btnRutBai = (Button)findViewById(R.id.button1);
        imageButton =  (ImageButton)findViewById(R.id.imageButton1);
        btnRutBai.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Random random = new Random();
		        int loaiBai = random.nextInt(3); // 0: co -> 3:bich
		        int viTriBai = random.nextInt(12);// 0: ach 1:hai 2:ba -> 3:bich
		        String bai = Integer.toString(viTriBai).concat(" "+Integer.toString(loaiBai));
		       // Toast.makeText(getApplicationContext(), bai, Toast.LENGTH_SHORT).show();
		        switch (loaiBai) {
				case 0:
				{
					imageButton.setImageResource(co[viTriBai]);
					break;
				}
				case 1:
				{
					imageButton.setImageResource(ro[viTriBai]);
					break;
				}
				case 2:
				{
					imageButton.setImageResource(chuong[viTriBai]);
					break;
				}
				case 3:
				{
					imageButton.setImageResource(bich[viTriBai]);
					break;
				}
		        }
			}
		        
			
		});
        
    }
}